package com.tdh.exception;

import com.tdh.pojo.Results;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@Component
@ControllerAdvice
public class MyExceptionResolver {

    private static final Logger logger = LoggerFactory.getLogger(MyExceptionResolver.class);

    @ResponseBody
    @ExceptionHandler(MyException.class)
    public <T> Results<T> resolveMyException(MyException e) {

        logger.error(e.getMessage(), e);

        return Results.error("服务器内部错误");

    }


    @ResponseBody
    @ExceptionHandler(Throwable.class)
    public <T> Results<T> resolveException(Throwable e) {

        logger.error("服务器内部错误", e);

        return Results.error("服务器内部错误");

    }
}
